package com.org.zp.ctrl.company;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.org.base.ctrl.ActivityTaskManager;
import com.org.base.ctrl.BaseActivity;
import com.org.base.util.HttpUtils;
import com.org.base.util.URLHelper;
import com.org.zp.R;

public class SchoolListInfoActivity extends BaseActivity{
	/** Called when the activity is first created. */

	private TextView title;
	private Button back_btn;
	private Button enable_btn;

	private TextView school_list_info_tv1, school_list_info_tv2,
			school_list_info_tv3, school_list_info_tv4, school_list_info_tv5,
			school_list_info_tv6, school_list_info_tv7;
	
	private String id = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.school_list_info);

		if (!(ActivityTaskManager.getInstance()
				.containsName("SchoolListInfoActivity"))) {
			ActivityTaskManager.getInstance().putActivity(
					"SchoolListInfoActivity", this);
		}

		back_btn = (Button) findViewById(R.id.back);
		enable_btn = (Button) findViewById(R.id.top_right_button);
		enable_btn.setVisibility(View.INVISIBLE);
		back_btn.setText("  返回");
		back_btn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ActivityTaskManager.getInstance().removeActivity(
						"SchoolListInfoActivity");
			}
		});
		title = (TextView) findViewById(R.id.headTitle);

		init();
	}

	private void init() {
		
		id = getIntent().getStringExtra("id");

		school_list_info_tv1 = (TextView) findViewById(R.id.school_list_info_tv1);
		school_list_info_tv2 = (TextView) findViewById(R.id.school_list_info_tv2);
		school_list_info_tv3 = (TextView) findViewById(R.id.school_list_info_tv3);
		school_list_info_tv4 = (TextView) findViewById(R.id.school_list_info_tv4);
		school_list_info_tv5 = (TextView) findViewById(R.id.school_list_info_tv5);
		school_list_info_tv6 = (TextView) findViewById(R.id.school_list_info_tv6);
		school_list_info_tv7 = (TextView) findViewById(R.id.school_list_info_tv7);
		
		new getComSchoolInfo().execute(URLHelper.mPrefix);

	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			ActivityTaskManager.getInstance().removeActivity(
					"SchoolListInfoActivity");
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	class getComSchoolInfo extends AsyncTask<String, Void, String> {

		@Override
		protected String doInBackground(String... params) {
			Map<String, String> map = new HashMap<String, String>(); // 登录时向服务器发送的参数
			map.put("act", "businessCollegePostDetail");
			map.put("postId", id);

			return HttpUtils.readHttp(params[0], map);// 网络操作，向服务器发送登录请求，获取返回信息

		}

		@Override
		protected void onPostExecute(String result) {

			if (result == null || result.equals("")) {
				// 发送解析数据 消息
				Toast toast = Toast.makeText(SchoolListInfoActivity.this, "失败",
						Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();

			} else if (result.equals("timeout")) {
				// 发送解析数据 消息
				Toast toast = Toast.makeText(SchoolListInfoActivity.this,
						"网络超时", Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();

			} else {
				try {
					JSONObject json = new JSONObject(result);
					String succeed = json.getString("succeed");
					if (succeed.equals("000")) {
						title.setText(json.getString("post_name"));
						school_list_info_tv1.setText("岗位名称：" + json.getString("post_name"));
						school_list_info_tv2.setText("工作职责：" + json.getString("post_duty"));
						school_list_info_tv3.setText("职务等级：" + json.getString("post_grade"));
						school_list_info_tv4.setText("工作描述：" + json.getString("post_description"));
						school_list_info_tv5.setText("胜任能力：" + json.getString("post_competence"));
						school_list_info_tv6.setText("培训课程：" + json.getString("post_training_course"));
						school_list_info_tv7.setText("合计总价： 共" + json.getString("post_total_money") + "元");
					} else {
						Toast toast = Toast.makeText(
								SchoolListInfoActivity.this, "获取失败",
								Toast.LENGTH_SHORT);
						toast.setGravity(Gravity.CENTER, 0, 0);
						toast.show();
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}

		}
	}

}